<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>合同跟进记录</title>
    <script src="../../../static/kaige/js/szload.js"></script>
    <style>
        .layui-form-pane .layui-form-label {
            width: 130px !important;
        }

        .layui-form-pane .layui-input-block {
            margin-left: 130px !important;
        }
    </style>
</head>

<body>
<div class="kaige-body">
    <table class="layui-table" id="pageTable" lay-filter="pageTable" lay-size="sm"></table>
    <input type="hidden" name="keywordsCache" value="{}"/>
</div>

<script>
    load_init_js([
        szoapcpath + '/static/kaige/js/date.js',
        szoapcpath + '/static/kaige/js/search.js',
        szoapcpath + '/static/kaige/js/xm-select.js'
    ], function () {
        layui.config({
            base: szoapcpath + '/static/kaige/layuiextend/'
        }).use(['element', 'table', 'form', 'layer', 'kaige', 'laydate', 'glfiles'], function () {
            var element = layui.element,
                layer = layui.layer,
                table = layui.table,
                form = layui.form,
                laydate = layui.laydate,
                kaige = layui.kaige,
                glfiles = layui.glfiles,
                $ = layui.$;

            window.kaige_page = {
                logout_url: '/index/logout',
                welcome: './pages/welcome.html',
                menus: [],
                leftmenu: [],
            };
            window.pagedict = parent.window.kaige_page.dict || {};

            form.render();


            kaige.table({
                elem: '#pageTable',
                url: "/crm.customer_record/index",
                id: 'pageTable',
                toolbar: '#dtoolbar',
                defaultToolbar: ['filter'],
                cols: [[
                    {field: 'id', title: '', align: 'center'},
                    {field: 'relation_name', title: '关联对象', align: 'center'},
                    {field: 'follow_type', title: '跟进类型', align: 'center', templet: "#follow_type_name"},
                    {field: 'follow_time', title: '跟进时间', align: 'center'},
                    {field: 'follow', title: '跟进状态', align: 'center', templet: "#follow_name"},
                    {field: 'content', title: '跟进内容', align: 'center'},
                    {field: 'next_time', title: '下次跟进时间', align: 'center'},
                    {field: 'create_time', title: '创建时间', align: 'center'},
                    {title: '操作', toolbar: '#dtrbar', align: 'center', width: 150, fixed: 'right'}
                ]]
            });

            window.show_employee = function () {
                laydate.render({
                    elem: '#next_time'
                    , type: 'date'
                });

                kaige.xmSelect({
                    id: 'relation_id',
                    url: '/select/Customer',
                    udata: {automatch: 1},
                    radio: true,
                    clickClose: true
                });

                $('#reminds_name').on('focus', function () { //rece_id_name 要调用的文本框
                    layer.open({
                        title: '选择适用对象',
                        content: szoa.client.path + '/pages/pmm/config/ugdc.html',
                        area: ['690px', '470px'],
                        type: 2,
                        success: function (layero, index) {
                            window.ugdcinfo = function (opt) {
                                $('#reminds_name').val(opt.names);
                                $('#reminds_id').val(opt.ids); // 隐藏的文本框存 id ,部门id(u1,u4),组id(g1,g2),部门根ID（c1,c9)与部门ID区别 根ID需要查找同所有子部门
                                layer.close(layer.index);
                            }
                        }
                    });
                });

            }

            //列表-监听表头工具栏事件dtoolbar
            table.on('toolbar(pageTable)', function (obj) {
                switch (obj.event) {
                    case 'btn-add':
                        btnadd();
                        break;
                }
            });

            //列表-监听单元格行工具事件dtrbar
            table.on('tool(pageTable)', function (obj) {
                var that = this;
                var data = obj.data;
                switch (obj.event) {
                    case 'edit':
                        baredit(data);
                        break;
                    case 'del':
                        bardel(data);
                        break;
                }
            });

            //添加
            function btnadd() {
                kaige.form({
                    url: "/crm.customer_record/add",
                    data: {},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class="layui-icon layui-icon-add-circle"></i> 添加 - 客户跟进记录',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {
                        show_employee();
                    },
                    postbefore: function (updata) {
                        updata.files_id = updata.form_files_id;
                        delete updata.form_files_id;
                        return updata;
                    },
                    getdata: function (res) {
                        var data = (res && res.data && res.data.fi) ? res.data.fi : null;
                        glfiles.form({
                            id: 'form',
                            is_edit: true,
                            data: data
                        });
                    }
                });
            }

            //编辑
            function baredit(d) {
                kaige.form({
                    url: "/crm.customer_record/edit",
                    data: {id: d.id},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class="layui-icon layui-icon-edit"></i> 编辑 - 客户跟进记录',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {
                        show_employee();
                    },
                    postbefore: function (updata) {
                        updata.files_id = updata.form_files_id;
                        delete updata.form_files_id;
                        return updata;
                    },
                    getdata: function (res) {
                        var data = (res && res.data && res.data.fi) ? res.data.fi : null;
                        glfiles.form({
                            id: 'form',
                            is_edit: true,
                            data: data
                        });
                    }
                });
            }

            //删除
            function bardel(d) {
                layer.confirm('您确定删除吗？', {
                    title: '<i class="layui-icon layui-icon-delete"></i> 删除确认',
                    btn: ['确认', '取消']
                }, function () {
                    $.post("/crm.customer_record/del", {id: d.id}, function (res) {
                        res.status && table.reload('pageTable');
                        layer.msg(res.msg);
                    });
                });
            };

        });
    });
</script>
<script type="text/html" id="dtrbar">
    <div class="layui-btn-group">
        <button class="layui-btn layui-btn-xs" lay-event="edit" title="编辑">编辑
        </button>
        <button class="layui-btn layui-btn-xs" lay-event="del" title="删除">删除
        </button>
    </div>
</script>
<script type="text/html" id="dtoolbar">
    <div class="layui-btn-container layui-form filter-form" lay-filter="searchform">
        <div class="layui-btn-group">
            <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-add" style="margin-top:2px;"><i
                    class="layui-icon layui-icon-add-circle"></i> 添加
            </button>
        </div>
    </div>
</script>

<script type="text/html" id="follow_type_name">
    {{# for(var ipd in pagedict.followType){ }}
    {{# if(d.follow_type ==ipd){ }}
    <span>{{ pagedict.followType[ipd] }}</span>
    {{# } }}
    {{# } }}
</script>

<script type="text/html" id="follow_name">
    {{# for(var ipd in pagedict.followStatus){ }}
    {{# if(d.follow ==ipd){ }}
    <span>{{ pagedict.followStatus[ipd] }}</span>
    {{# } }}
    {{# } }}
</script>

<script type="text/html" id="kaige_form_html">
    <form class="layui-form layui-form-pane kaige-body-form" style="padding: 5px;" lay-filter="kaige_form_lay_filter">
        {{# if(d.id){ }}
        <input type="hidden" name="id" value="{{ d.id }}"/>
        {{# } }}
        <div class="layui-form-item">
            <label class="layui-form-label">跟进类型</label>
            <div class="layui-input-inline">
                <select name="follow_type" lay-verify="required">
                    {{# lay.each(pagedict.followType,function(index,item){
                    if(index == ''){
                    top.layer.msg('系统字典->跟进类型未配置完成，值不能为空');
                    }
                    }}
                    <option value="{{ index }}" {{ d.follow_type== index ?
                    'selected' :'' }}>{{ item }}</option>
                    {{# }) }}
                </select>
            </div>

            <label class="layui-form-label">下次跟进时间</label>
            <div class="layui-input-inline">
                <input id="next_time" name="next_time" value="{{ d.next_time || '' }}" class="layui-input" type="text">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">跟进内容</label>
            <div class="layui-input-block">
                <input name="content" value="{{ d.content || '' }}" class="layui-input" type="text">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">跟进状态</label>
            <div class="layui-input-inline">
                <select name="follow" lay-verify="required">
                    {{# lay.each(pagedict.followStatus,function(index,item){
                    if(index == ''){
                    top.layer.msg('系统字典->客户跟进状态未配置完成，值不能为空');
                    }
                    }}
                    <option value="{{ index }}" {{ d.follow== index ?
                    'selected' :'' }}>{{ item }}</option>
                    {{# }) }}
                </select>
            </div>
            <label class="layui-form-label">提醒人员列表</label>
            <div class="layui-input-inline">
                <input id="reminds_name" type="text" value="{{ d.reminds_name || '' }}" name="reminds_name"
                       class="layui-input"/>
                <input id="reminds_id" type="hidden" value="{{ d.reminds_id || '' }}" name="reminds_id"
                       class="layui-input"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">关联ID</label>
            <div class="layui-input-inline">
                {{# if(d.id){ }}
                    <input type="hidden" id="relation_id" value="{{ d.relation_id || '' }}" name="relation_id" />
                    <input type="text" id="relation_id_name" value="{{ d.relation_name || '' }}" name="relation_name" class="layui-input" readonly/>
                {{# }else{ }}
                    <div id="relation_id_select_box"></div>
                    <input type="hidden" id="relation_id" value="{{ d.relation_id || '' }}" name="relation_id"/>
                    <input type="hidden" id="relation_id_name" value="{{ d.relation_name || '' }}" name="relation_name"/>
                {{# } }}
            </div>
        </div>


        <div class="layui-form-item" id="form_files_gl_html"></div>

        <div class="layui-form-item layui-hide">
            <button class="layui-hide" lay-submit="" id="kaige_form_btn_save" lay-filter="kaige_form_btn_save">保存数据
            </button>
        </div>
    </form>
</script>
</body>
</html>